<?php

namespace app\admin\model;

use think\Model;


class Ordergoods extends Model
{

    

    

    // 表名
    protected $name = 'litestore_order_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'deduct_stock_type_text',
        'spec_type_text',
        'status_text'
    ];
    

    
    public function getDeductStockTypeList()
    {
        return ['10' => __('Deduct_stock_type 10'), '20' => __('Deduct_stock_type 20')];
    }

    public function getSpecTypeList()
    {
        return ['10' => __('Spec_type 10'), '20' => __('Spec_type 20')];
    }

    public function getStatusList()
    {
        return ['16' => __('Status 16')];
    }


    public function getDeductStockTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deduct_stock_type']) ? $data['deduct_stock_type'] : '');
        $list = $this->getDeductStockTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSpecTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['spec_type']) ? $data['spec_type'] : '');
        $list = $this->getSpecTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function supplier()
    {
        return $this->belongsTo('Mallsupplier', 'supplier_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function spec()
    {
        return $this->belongsTo('Litestoregoodsspec','spec_sku_id','spec_sku_id');
    }

}
